<template>
  <div class="container">
    <div class="weui_cells_title">住院号：</div>
    <div class="weui_cells weui_cells_access" style="margin-top:10px;">
      <a @click="selectWard" class="weui_cell" href="javascript:;">
        <div class="weui_cell_hd">
          <i class="fa fa-credit-card-alt fa-2x icon-color" style="width:45px;margin-right:5px;display:block;"></i>
        </div>
        <div class="weui_cell_bd weui_cell_primary">
          <p>{{ward?ward.name:''}}</p>
          <p>{{ward?ward.num:''}}</p>
        </div>
        <div class="weui_cell_ft">
          选住院号
        </div>
      </a>
    </div>
    <div class="weui_cells_title" v-show="showEmpty">{{emptyMsg}}</div>
    <div v-show="showPrepay" class="weui_cells_title">住院预缴金记录</div>
    <div v-show="showPrepay" class="weui_cells weui_cells_access" style="margin-top:10px;">
      <a v-for="wd in wardDeposits" class="weui_cell" href="javascript:;">
        <!-- <div class="weui_cell_hd">
          <i class="fa fa-hospital-o icon-color" style="width:20px;margin-right:5px;display:block;"></i>
        </div> -->
        <div class="weui_cell_bd weui_cell_primary">
          <p>住院流水号：<span class="am-ft-blue">{{wd.flowNo}}</span></p>
          <p>押金单号：<span class="am-ft-blue">{{wd.depositNo}}</span></p>
          <p>交易时间：<span class="am-ft-blue">{{wd.payDate}}</span></p>
          <p>金额：<span class="am-ft-blue">{{wd.amt}} 元</span></p>
          <p>押金状态：<span class="am-ft-blue">{{wd.state}}</span></p>
        </div>
      </a>
    </div>
    <partial name="footer-copyright"></partial>
  </div>
</template>
<style scoped>
.blue_tag {
  background-color: #0ae;
  color: #fff;
  font-size: 13px;
  padding: 2px 4px;
  border: none;
  vertical-align: middle;
  -moz-border-radius: 3px;
  -webkit-border-radius: 3px;
  border-radius: 3px;
}

.orange_tag {
  background-color: #ff8208;
  color: #fff;
  font-size: 13px;
  padding: 2px 4px;
  border: none;
  vertical-align: middle;
  -moz-border-radius: 3px;
  -webkit-border-radius: 3px;
  border-radius: 3px;
}

span.label {
  display: inline-block;
  width: 100px;
}

span.info {
  color: #0ae;
}
</style>
<script>
import _ from 'underscore'

export default {
  name: 'searchPrepayView',
  data: function () {
    return {
      showEmpty: false,
      emptyMsg: '',
      showPrepay: false,
      wardDeposits: []
    }
  },
  vuex: {
    getters: {
      ward: ({ ward }) => _.findWhere(ward.wards, { isSelected: true })
    }
  },
  methods: {
    selectWard: function () {
      this.$router.go({ name: 'selectWard' })
    },
    getInpatientPrepayList: function () {
      if (!this.ward) {
        return
      }
      var self = this

      this.$ajax.get('GetInpatientPrepayList', 'Inpatient', {
        wardId: this.ward.id
      }).then(function (data) {
        if (data.ResultCode !== '0') {
          self.showEmpty = true
          self.emptyMsg = data.ResultMsg
        } else {
          self.showPrepay = true
          self.wardDeposits = _.map(data.WardDeposits, function (val) {
            return {
              flowNo: val.FlowNo,
              depositNo: val.DepositNo,
              amt: val.Amt,
              payDate: val.PayDate,
              state: val.State
            }
          })
        }
      })
    }
  },
  ready: function () {
    this.$watch('ward', function (val) {
      this.getInpatientPrepayList()
    })

    this.getInpatientPrepayList()
  }
}
</script>
